function Searcher(gtdinboxPage){
	this._gtdinboxPage = gtdinboxPage;
	this._querySize = 25;
};

Searcher.prototype.searchCurrentQuery = function(callbackFinish){
	// Take current location, and retrieve the search query from it
	var query = this._gtdinboxPage.gmailDOM.extractSearchQueryFromURL(this._gtdinboxPage.doc.location.href);
	this.search(query, callbackFinish);
};

Searcher.prototype.search = function(query, callbackFinish){
	// Take the q, send it as an XML http request, and pass the result (an array) to _searchCallback
	// Create a new thread list to accept this array

try{
	this.threadList = new ThreadList(this._gtdinboxPage);
	this._gtdinboxPage.gmailDOM.search(query, 0, this._querySize, GIPROTOTYPE.bind(this, this._searchCallback), callbackFinish );
	
}catch(e){
	if( GTDDEBUGMODE ) alert( "Searcher search\n" + e.toString());
}
};

Searcher.prototype._searchCallback = function(threadArray, query, currentOffset, callbackFinish){
try{
	var numberNewThreads = this.threadList.parseAjaxResponse(threadArray[0]);
	this._gtdinboxPage.unsafeWindow.console.log(numberNewThreads + "/" + this.threadList._threads.length);
	this._gtdinboxPage.unsafeWindow.console.log(threadArray[0]);
	
	if( numberNewThreads >= this._querySize ){	// Could still be more
		this._gtdinboxPage.unsafeWindow.console.log("query again: " + query);
		this._gtdinboxPage.gmailDOM.search(query, currentOffset + this._querySize, this._querySize, GIPROTOTYPE.bind(this, this._searchCallback), callbackFinish );
	}else{	// Finished
		this._gtdinboxPage.unsafeWindow.console.log("finished");
		if( callbackFinish ) callbackFinish();
		this._gtdinboxPage.unsafeWindow.console.log(this.threadList._threads);
	}
}catch(e){
	if( GTDDEBUGMODE ) alert( "Searcher _searchCallback\n" + e.toString());
}
};

Searcher.prototype._parseAjaxResponse = function(threadArray){

};